package com.maya.medicalwastes.util;

import android.content.Context;
import android.hardware.usb.UsbDevice;
import android.hardware.usb.UsbManager;

import timing.ukulele.serialport.driver.UsbSerialDriver;
import timing.ukulele.serialport.driver.UsbSerialProber;

/**
 * @author created by fuguoyong
 * 版本：1.0
 * 创建日期：2020-12-08 09
 * 描述：UsbManagerUtil
 */
public class UsbManagerUtil {

    public static UsbDevice getDevices(Context context) {
        UsbManager usbManager = (UsbManager) context.getSystemService(Context.USB_SERVICE);
        UsbSerialProber usbDefaultProber = UsbSerialProber.getDefaultProber();
        UsbSerialProber usbCustomProber = CustomProber.getCustomProber();
        for (UsbDevice device : usbManager.getDeviceList().values()) {
            UsbSerialDriver driver = usbDefaultProber.probeDevice(device);
            if (driver == null) {
                driver = usbCustomProber.probeDevice(device);
            }
            if (driver != null) {
                if (driver.getDevice().getProductName().contains("USB")) {
                   return device;
                }


            }
        }

        return null;
    }
}
